package com.webmall.servlet.cate;

import com.webmall.service.webmall_CateDao;
import com.webmall.service.webmall_UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/manageHtml/admin_doCateDelete")
public class doCateDelete extends HttpServlet {


    //用于单个删除
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        String id = request.getParameter("id");

        //删除操作
        int count= webmall_CateDao.deleteByID(id);


        //成功或失败重定位到哪儿
        if (count >0){
  //          response.sendRedirect("admin_doUserShow");//成功
            response.sendRedirect(request.getContextPath()+"/manageHtml/admin_CateSelect?");//修改成功 返回到当前页

//

        }else {//失败 用输出流输出 js语句
            PrintWriter out = response.getWriter();
            out.write("<script>");
            out.write("alert('用户删除失败')");
            out.write("location.href=<%=request.getContextPath()%>'/manageHtml/admin_CateSelect？'");
            out.write("</script>");

        }

    }
}
